<template>
  <view class="container">
    <view class="page-title">附近店铺</view>
    <view class="shop-list">
      <view class="shop-item" v-for="shop in shops" :key="shop.id" @click="goToShopDetail(shop.id)">
        <image :src="shop.imgUrl" mode="aspectFit" class="shop-logo"></image>
        <view class="shop-info">
          <text class="shop-name">{{ shop.name }}</text>
          <text>月售: {{ shop.sales }} 起送: {{ shop.expressLimit }} 基础运费: {{ shop.expressPrice }}</text>
          <text class="promotion" v-if="shop.slogan">{{ shop.slogan }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      shops: []
    };
  },
  onLoad() {
    this.fetchShops();
  },
  methods: {
    async fetchShops() {
      try {
        const response = await this.$axios.get('http://localhost:3000/shops');
        this.shops = response.data;
      } catch (error) {
        console.error('获取店铺数据失败', error);
      }
    },
    goToShopDetail(shopId) {
      uni.navigateTo({
        url: `/pages/shopDetail/shopDetail?id=${shopId}`
      });
    }
  }
};
</script>

<style scoped>
.container {
  background-color: #f8f9fa;
  padding: 20px;
}

.page-title {
  font-size: 20px;
  color: #333;
  font-weight: 600;
  margin-bottom: 15px;
}

.shop-list {
  width: 100%;
}

.shop-item {
  display: flex;
  align-items: center;
  background-color: #fff;
  border-radius: 10px;
  padding: 15px;
  margin-bottom: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.shop-logo {
  width: 60px;
  height: 60px;
  margin-right: 15px;
}

.shop-name {
  font-size: 16px;
  color: #333;
  margin-bottom: 5px; 
  display: block;
}

.shop-info {
  flex: 1;
  font-size: 14px;
  color: #666;
}

.promotion {
  color: #FF5722;
  margin-top: 5px;
   display: block;
}
</style>